package br.usp.wta.inductor;

import java.io.FileWriter;
import java.io.IOException;

import br.usp.language.automata.StateMachine;
import br.usp.language.syntax.grammar.ContextFreeGrammar;
import br.usp.language.syntax.grammar.ProductionRule;

public class GrammarInductor {
    
    public static String TRAINING = "resources/training/realtraining/all2.txt";
    public static String GRAMMAR = "resources/inferedgrammar.txt";

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        
        PrefixSufixGenerator generator = new PrefixSufixGenerator(TRAINING, null);
        generator.generate();
        StateMachine Ap = generator.getPrefixAut();
        StateMachine As = generator.getSufixAut();
        JJ98 jj98 = new JJ98();
        StateMachine Ac = jj98.geraAc(Ap, As);
        Ivone ivone = new Ivone();
        ContextFreeGrammar grammar = ivone.inferAPE(Ac);
        
        FileWriter wr = new FileWriter(GRAMMAR);
        for (ProductionRule rule : grammar.getRules()) {
            wr.write(rule.toString() + System.getProperty("line.separator"));
        }
        wr.close();
    }

}
